import { axiosInstance } from './axios-instance';

export type QuestionType = 'CHOICE' | 'TRUE_FALSE' | 'FILL_BLANK' | 'SHORT_ANSWER';

export interface Question {
  id: number;
  type: QuestionType;
  content: string;
  options: string[];
  answer: string;
  explanation: string;
  subject: string;
  createdAt: string;
  updatedAt: string;
}

export interface CreateQuestionDto {
  type: QuestionType;
  content: string;
  options: string[];
  answer: string;
  explanation: string;
  subject: string;
  score?: number;
}

export interface UpdateQuestionDto {
  type?: QuestionType;
  content?: string;
  options?: string[];
  answer?: string;
  explanation?: string;
  subject?: string;
  score?: number;
}

export const getQuestions = async (): Promise<Question[]> => {
  const response = await axiosInstance.get('/questions');
  return response.data;
};

export const getQuestion = async (id: number): Promise<Question> => {
  const response = await axiosInstance.get(`/questions/${id}`);
  return response.data;
};

export const createQuestion = async (data: CreateQuestionDto): Promise<Question> => {
  const response = await axiosInstance.post('/questions', data);
  return response.data;
};

export const updateQuestion = async (id: number, data: UpdateQuestionDto): Promise<Question> => {
  const response = await axiosInstance.patch(`/questions/${id}`, data);
  return response.data;
};

export const deleteQuestion = async (id: number): Promise<Question> => {
  const response = await axiosInstance.delete(`/questions/${id}`);
  return response.data;
};